import request from '@/utils/request'

export interface LoginParams {
  username: string
  password: string
}

export interface RegisterParams {
  username: string
  password: string
  email: string
  nickname?: string
}

export interface UserInfo {
  id: number
  username: string
  nickname: string
  email: string
  phone?: string
  avatar?: string
}

export interface LoginResult {
  token: string
  userInfo: UserInfo
}

// 用户登录
export const login = (data: LoginParams) => {
  return request.post<LoginResult>('/api/user/login', data)
}

// 用户注册
export const register = (data: RegisterParams) => {
  return request.post('/api/user/register', data)
}

// 获取用户信息
export const getUserInfo = () => {
  return request.get<UserInfo>('/api/user/info')
}

// 用户退出
export const logout = () => {
  return request.post('/api/user/logout')
}